<?php
/************************
 *  Codenova.pl Project
 *  Created by: Kamil Mrzygłód
 *
 *  (c) 2013 by Codenova.pl
 *  All Right Reserved
 ***********************/

namespace Gotcha\App\Types;

use Gotcha\App\Extensions\GotchaCulturesExtension;
use Gotcha\App\Extensions\GotchaErrorsExtension;
use Gotcha\App\Extensions\GotchaLogsExtension;

class Bool {
    public $bool;

    public function __construct($value) {
        // Try to set variable type
        if (!settype($this->bool, 'bool')) {
            GotchaLogsExtension::createNewLogEntry(new String(GotchaCulturesExtension::getTranslation(new String('CANNOT_CONVERT_PARAMETER_TO_TYPE'))), new String($value));
            GotchaErrorsExtension::throwError(new String(GotchaCulturesExtension::getTranslation(new String('CANNOT_CONVERT_PARAMETER_TO_TYPE'))), new String($value));
            exit;
        }

        // Attach value
        $this->bool = $value;
    }

    public function __toString() {
        if (!is_null($this->bool)) {
            return $this->bool;
        } else {
            // Return empty string
            return '';
        }

    }

    public function __destruct() {
        unset($this->bool);
    }
}